﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var renderTable;
        var userType = 0;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            treetable: 'treetable-lay/treetable',
            index: 'lib/index'
        }).use(['table', 'form', 'treetable', 'index', 'laydate'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , element = layui.element
                , laydate = layui.laydate;

            // 渲染表格
            renderTable = table.render({
                elem: '#table-datalist'
                , url: '/Console/MtService/GetMt5groupListJson'
                , toolbar: '#table-datalist-toolbar'
                , limit: 20
                , title: 'MT5服务器设置列表'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'index', title: '序号' }
                    , { field: 'MTgroups', title: 'MT5组别' }
                    , { field: 'accountStartNo', title: '账号起始编号' }
                    , { field: 'accountEndNo', title: '账号结束编号' }
                    , { field: 'operate', fixed: 'right', title: '操作', toolbar: '#table-datalist-bar', width: 300 }
                ]]
                , id: "tableReload"
                , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                , done: function (res) {
                    if (res.count == 0) {
                        $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                    }
                    layer.closeAll('loading');

                    /**多语言初始化 */
                    top.SetListPageLanguage(layui);
                    top.SetSelectLanguage(layui);
                    layui.form.render("select");
                }
            });


            //头工具栏事件
            table.on('toolbar(table-datalist)', function (obj) {
                switch (obj.event) {
                    case 'addNew':
                        top.OpenPageByKey(layui, "addNew", 2, '1200px', '500px', '/Console/MtService/AddServerSetting');
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    top.OpenPageByKey(layui, "updateServerSettings", 2, '1200px', '500px', '/Console/MtService/Edit?id=' + data.index);

                } else if (obj.event === 'del') {
                    var postData = {
                        id: data.index
                    };
                    top.ConfirmByKey(layui, 'confirmDelete', postData, "/Console/MtService/Delete", "POST", "deleteSuccess", "deleteFail", function () {
                        table.reload("tableReload");
                    });

                }

            });

            form.on('switch(table-state)', function (obj) {
                var state = 1;
                if (obj.elem.checked) {
                    state = 1;
                } else {
                    state = 0;
                }
                $.ajax({
                    type: "POST",
                    url: "/Console/MtService/UpdateState",
                    data: {
                        id: this.value,
                        intState: state
                    }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                        table.reload("table-datalist");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            top.ShowMessageByKey(layui, "submitSuccess", 6, 1000, function () {
                                renderTable();
                            });
                        } else {
                            /**提示语弹框 */
                            top.AlertByKey(layui, "submitFail", 0);
                        }
                        layer.closeAll('loading');
                    }
                });
            });

        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-tab-content">
                        <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                        <script type="text/html" id="table-datalist-toolbar">
                            <div class="layui-btn-container">
                                <button class="layui-btn layui-btn-sm" lay-event="addNew">新增</button>
                            </div>
                        </script>
                        <script type="text/html" id="table-datalist-bar">
                            <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
                            <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
                            <button class="layui-btn layui-btn-sm" lay-event="groups">组别</button>
                            <button class="layui-btn layui-btn-sm" lay-event="accountType">账号类型</button>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

